package DEEPERsource.DEEPERsource.source.corpus;

import java.util.Iterator;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import deeper.Interaction;

/**
 * Class intended to provide printing facilities for composite texts.
 * @author tfayruzo
 *
 */
public class TextPresentationBuilder {
	private static Log _log = LogFactory.getLog(TextPresentationBuilder.class);
	
	private StringBuffer text;
	private String[] params;
	private boolean arff = false;
	private boolean directed = false;
	
	public void init(String...format){
		text = new StringBuffer("");
		params = format;
		for(String param : params){
			if(param.equals("arff")){
				arff = true;
			}
			if(param.equals("directed")){
				directed = true;
			}
		}
		if(arff)
			text.append(getARFFHeader());
	}
	
	public void addARFF(Text piece){
		if(piece instanceof Corpus){
			text.append("%").append(piece.id).append("\n");
		}else if(piece instanceof Abstract){
			text.append("%").append(piece.id).append("\n");
		}else if(piece instanceof Sentence){
			Sentence s = (Sentence) piece;
			_log.info(s.text);
			text.append("%").append(s.text).append("\n");
			for(Iterator<Interaction> it = s.interactions().iterator(); it.hasNext();){
				Interaction i = it.next();
				if(i.depPath==null){
					text.append("No path").append("\n");
				}else{
					//text.append(i.depPath.arffDepString()).append("\t").append(i.status).append("\n");
				}				
			}
		}
	}
	
		
	public String getText(){
		return text.toString();
	}
	
	private String getARFFHeader(){
		StringBuffer result = new StringBuffer("% ARIFF file for protein interaction classification\n");
		result.append("@relation interaction\n");
		String depRelationTypes = "{ dep, aux, auxpass, cop, conj, conj_nor, conj_only, conj_negcc, conj_versus, conj_and, conj_but, conj_or, cc, arg, subj, nsubj, nsubjpass, csubj, "
			+ "measure, comp, obj, dobj, iobj, pobj, attr, ccomp, xcomp, compl, mark, rel, acomp, agent, csubjpass, "
			+ "ref, expl, mod, advcl, purpcl, tmod, rcmod, amod, infmod, partmod, num, number, appos,"
			+ "nn, abbrev, advmod, neg, poss, possessive, prt, det, prep, "
			+ "prep_onto, prep_involving, prep_while, prep_toward, prep_due_to, prep_based_on, prep_compared_to, prep_against, prep_over, prep_compared_with, prep_including, prep_concerning, prep_regarding, prep_whether, prep_despite, prep_on, prep_of, prep_under, prep_in, prep_as, prep_for, prep_during, prep_at, prep_from, prep_after, prep_before, prep_to, prep_by, prep_into, prep_through, prep_between, prep_with, prep_via, prep_upon, prep_like, prep_near, prep_within, prep_following, prep_inside, prep_than, prep_beyond, prep_unlike, "
			+ "prepc_from, prepc_since, prepc_on, prepc_at, prepc_of, prepc_for, prepc_in, prepc_by, prepc_despite, sdep, xsubj }";
		result.append("\n");
		result.append("@attribute depL1 ").append(depRelationTypes).append("\n");
		result.append("@attribute depL2 ").append(depRelationTypes).append("\n");
		result.append("@attribute depL3 ").append(depRelationTypes).append("\n");
		result.append("@attribute depL4 ").append(depRelationTypes).append("\n");
		result.append("@attribute depL5 ").append(depRelationTypes).append("\n");
		result.append("@attribute depL6 ").append(depRelationTypes).append("\n");
		result.append("@attribute depR1 ").append(depRelationTypes).append("\n");
		result.append("@attribute depR2 ").append(depRelationTypes).append("\n");
		result.append("@attribute depR3 ").append(depRelationTypes).append("\n");
		result.append("@attribute depR4 ").append(depRelationTypes).append("\n");
		result.append("@attribute depR5 ").append(depRelationTypes).append("\n");
		result.append("@attribute depR6 ").append(depRelationTypes).append("\n");
		result.append("@attribute sLeft numeric\n");
		result.append("@attribute sRight numeric\n");
		result.append("@attribute lDistance numeric\n");
		result.append("@attribute rDistance numeric\n");
		if(directed){
			result.append("@attribute reaction {none,straight,inverse}\n\n");
		}else{
			result.append("@attribute reaction {yes, no}\n\n");
		}
		result.append("@data\n");
		return result.toString();
	}
}
